/**
 *
 */
import Util;
import OSS;
import OpenPlatform;
import OSSUtil;
import FileForm;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('farui', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateTextFileRequest {
  clientToken?: string(name='ClientToken', example='e9a93201-7e96-4dc1-9678-2832fc132d08'),
  createTime?: string(name='CreateTime', example='1714476549'),
  textFileName?: string(name='TextFileName'),
  textFileUrl?: string(name='TextFileUrl'),
}

model CreateTextFileAdvanceRequest {
  clientToken?: string(name='ClientToken', example='e9a93201-7e96-4dc1-9678-2832fc132d08'),
  createTime?: string(name='CreateTime', example='1714476549'),
  textFileName?: string(name='TextFileName'),
  textFileUrlObject?: readable(name='TextFileUrl'),
}

model CreateTextFileResponseBody = {
  code?: string(name='Code', example='Request.Signature.Error'),
  data?: {
    textFileId?: string(name='TextFileId', example='36d6447d277c4a1c9fd0def1d16341f1'),
    textFileName?: string(name='TextFileName'),
    textFileUrl?: string(name='TextFileUrl'),
  }(name='Data'),
  httpStatusCode?: long(name='HttpStatusCode', example='200'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', description='Id of the request', example='81E6F6D2-8ACB-5BDA-9C7C-4D6268CD9652'),
  success?: boolean(name='Success', example='True'),
}

model CreateTextFileResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: CreateTextFileResponseBody(name='body'),
}

/**
 * @summary 上传合同文件
 *
 * @param request CreateTextFileRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return CreateTextFileResponse
 */
async function createTextFileWithOptions(WorkspaceId: string, request: CreateTextFileRequest, headers: map[string]string, runtime: Util.RuntimeOptions): CreateTextFileResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.clientToken)) {
    body['ClientToken'] = request.clientToken;
  }
  if (!Util.isUnset(request.createTime)) {
    body['CreateTime'] = request.createTime;
  }
  if (!Util.isUnset(request.textFileName)) {
    body['TextFileName'] = request.textFileName;
  }
  if (!Util.isUnset(request.textFileUrl)) {
    body['TextFileUrl'] = request.textFileUrl;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CreateTextFile',
    version = '2024-06-28',
    protocol = 'HTTPS',
    pathname = `/${OpenApiUtil.getEncodeParam(WorkspaceId)}/data/textFile`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 上传合同文件
 *
 * @param request CreateTextFileRequest
 * @return CreateTextFileResponse
 */
async function createTextFile(WorkspaceId: string, request: CreateTextFileRequest): CreateTextFileResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return createTextFileWithOptions(WorkspaceId, request, headers, runtime);
}

async function createTextFileAdvance(WorkspaceId: string, request: CreateTextFileAdvanceRequest, headers: map[string]string, runtime: Util.RuntimeOptions): CreateTextFileResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'FaRui',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var createTextFileReq = new CreateTextFileRequest{};
  OpenApiUtil.convert(request, createTextFileReq);

  if(!Util.isUnset(request.textFileUrlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.textFileUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    createTextFileReq.textFileUrl = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var createTextFileResp = createTextFileWithOptions(WorkspaceId, createTextFileReq, headers, runtime);
  return createTextFileResp;
}

model RunContractResultGenerationRequest {
  appId?: string(name='appId', example='farui'),
  assistant?: {
    metaData?: {
      customRuleConfig?: {
        customRules?: [ 
          {
            riskLevel?: string(name='riskLevel', example='high'),
            ruleDesc?: string(name='ruleDesc'),
            ruleTitle?: string(name='ruleTitle'),
          }
        ](name='customRules'),
      }(name='customRuleConfig'),
      fileId?: string(name='fileId', example='9a6b1ba60d9944249363ec3cc1529b7b'),
      position?: string(name='position', example='1'),
      ruleTaskId?: string(name='ruleTaskId', example='b265b416-ca1f-425d-9340-c968f39624e1'),
      rules?: [ 
        {
          riskLevel?: string(name='riskLevel', example='medium'),
          ruleSequence?: string(name='ruleSequence', example='2.1'),
          ruleTag?: string(name='ruleTag'),
          ruleTitle?: string(name='ruleTitle'),
        }
      ](name='rules'),
    }(name='metaData'),
    type?: string(name='type', example='contract_examime'),
    version?: string(name='version', example='1.0.0'),
  }(name='assistant'),
  stream?: boolean(name='stream', example='true'),
}

model RunContractResultGenerationShrinkRequest {
  appId?: string(name='appId', example='farui'),
  assistantShrink?: string(name='assistant'),
  stream?: boolean(name='stream', example='true'),
}

model RunContractResultGenerationResponseBody = {
  code?: string(name='Code', example='null'),
  message?: string(name='Message', example='null'),
  output?: {
    result?: {
      examineBrief?: string(name='examineBrief'),
      examineResult?: string(name='examineResult'),
      riskLevel?: string(name='riskLevel', example='high'),
      ruleSequence?: string(name='ruleSequence', example='1.1'),
      ruleTag?: string(name='ruleTag'),
      ruleTitle?: string(name='ruleTitle'),
      subRisks?: [ 
        {
          originalContent?: string(name='originalContent'),
          resultContent?: string(name='resultContent'),
          resultType?: string(name='resultType'),
          riskBrief?: string(name='riskBrief'),
          riskClause?: string(name='riskClause'),
          riskExplain?: string(name='riskExplain'),
        }
      ](name='subRisks'),
    }(name='result'),
    resultTaskId?: string(name='resultTaskId', example='eaa56e1e-e205-4f5e-926e-5e2269ae7f68'),
  }(name='Output'),
  requestId?: string(name='RequestId', example='744419D0-671A-5997-9840-E8AE48356194'),
  success?: boolean(name='Success', example='True'),
  usage?: {
    input?: long(name='input', example='5'),
    unit?: string(name='unit', example='page'),
  }(name='Usage'),
  httpStatusCode?: string(name='httpStatusCode', example='200'),
}

model RunContractResultGenerationResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RunContractResultGenerationResponseBody(name='body'),
}

/**
 * @summary 生成合同审查结果
 *
 * @param tmpReq RunContractResultGenerationRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return RunContractResultGenerationResponse
 */
async function runContractResultGenerationWithOptions(workspaceId: string, tmpReq: RunContractResultGenerationRequest, headers: map[string]string, runtime: Util.RuntimeOptions): RunContractResultGenerationResponse {
  Util.validateModel(tmpReq);
  var request = new RunContractResultGenerationShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.assistant)) {
    request.assistantShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.assistant, 'assistant', 'json');
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.appId)) {
    body['appId'] = request.appId;
  }
  if (!Util.isUnset(request.assistantShrink)) {
    body['assistant'] = request.assistantShrink;
  }
  if (!Util.isUnset(request.stream)) {
    body['stream'] = request.stream;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RunContractResultGeneration',
    version = '2024-06-28',
    protocol = 'HTTPS',
    pathname = `/${OpenApiUtil.getEncodeParam(workspaceId)}/farui/contract/result/genarate`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 生成合同审查结果
 *
 * @param request RunContractResultGenerationRequest
 * @return RunContractResultGenerationResponse
 */
async function runContractResultGeneration(workspaceId: string, request: RunContractResultGenerationRequest): RunContractResultGenerationResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return runContractResultGenerationWithOptions(workspaceId, request, headers, runtime);
}

model RunContractRuleGenerationRequest {
  appId?: string(name='appId', example='farui'),
  assistant?: {
    metaData?: {
      fileId?: string(name='fileId', example='9a6b1ba60d9944249363ec3cc1529b7b'),
      position?: string(name='position', example='1'),
    }(name='metaData'),
    type?: string(name='type', example='contract_examime'),
    version?: string(name='version', example='1.0.0'),
  }(name='assistant'),
  stream?: boolean(name='stream', example='true'),
}

model RunContractRuleGenerationShrinkRequest {
  appId?: string(name='appId', example='farui'),
  assistantShrink?: string(name='assistant'),
  stream?: boolean(name='stream', example='true'),
}

model RunContractRuleGenerationResponseBody = {
  code?: string(name='Code', example='null'),
  message?: string(name='Message', example='null'),
  output?: {
    ruleTaskId?: string(name='ruleTaskId', example='b265b416-ca1f-425d-9340-c968f39624e9'),
    rules?: [ 
      {
        riskLevel?: string(name='riskLevel', example='medium'),
        ruleSequence?: string(name='ruleSequence', example='1.1'),
        ruleTag?: string(name='ruleTag'),
        ruleTitle?: string(name='ruleTitle'),
      }
    ](name='rules'),
  }(name='Output'),
  requestId?: string(name='RequestId', example='744419D0-671A-5997-9840-E8AE48356194'),
  success?: boolean(name='Success', example='True'),
  usage?: {
    input?: long(name='input', example='5'),
    unit?: string(name='unit', example='page'),
  }(name='Usage'),
  httpStatusCode?: int32(name='httpStatusCode', example='200'),
}

model RunContractRuleGenerationResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RunContractRuleGenerationResponseBody(name='body'),
}

/**
 * @summary 生成合同审查规则
 *
 * @param tmpReq RunContractRuleGenerationRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return RunContractRuleGenerationResponse
 */
async function runContractRuleGenerationWithOptions(workspaceId: string, tmpReq: RunContractRuleGenerationRequest, headers: map[string]string, runtime: Util.RuntimeOptions): RunContractRuleGenerationResponse {
  Util.validateModel(tmpReq);
  var request = new RunContractRuleGenerationShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.assistant)) {
    request.assistantShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.assistant, 'assistant', 'json');
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.appId)) {
    body['appId'] = request.appId;
  }
  if (!Util.isUnset(request.assistantShrink)) {
    body['assistant'] = request.assistantShrink;
  }
  if (!Util.isUnset(request.stream)) {
    body['stream'] = request.stream;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RunContractRuleGeneration',
    version = '2024-06-28',
    protocol = 'HTTPS',
    pathname = `/${OpenApiUtil.getEncodeParam(workspaceId)}/farui/contract/rule/genarate`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 生成合同审查规则
 *
 * @param request RunContractRuleGenerationRequest
 * @return RunContractRuleGenerationResponse
 */
async function runContractRuleGeneration(workspaceId: string, request: RunContractRuleGenerationRequest): RunContractRuleGenerationResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return runContractRuleGenerationWithOptions(workspaceId, request, headers, runtime);
}

model RunLegalAdviceConsultationRequest {
  appId?: string(name='appId', example='farui'),
  assistant?: {
    id?: string(name='id', example='assitant_abc_123'),
    metaData?: map[string]string(name='metaData'),
    type?: string(name='type', example='legal_advice_consult'),
    version?: string(name='version', example='1.0.0'),
  }(name='assistant'),
  stream?: boolean(name='stream', example='true'),
  thread?: {
    messages?: [ 
      {
        content?: string(name='content'),
        role?: string(name='role', example='user'),
      }
    ](name='messages'),
  }(name='thread'),
}

model RunLegalAdviceConsultationShrinkRequest {
  appId?: string(name='appId', example='farui'),
  assistantShrink?: string(name='assistant'),
  stream?: boolean(name='stream', example='true'),
  threadShrink?: string(name='thread'),
}

model RunLegalAdviceConsultationResponseBody = {
  code?: string(name='Code', example='Request.Signature.Error'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='744419D0-671A-5997-9840-E8AE48356194'),
  responseMarkdown?: string(name='ResponseMarkdown'),
  round?: int32(name='Round', example='1'),
  status?: string(name='Status'),
  success?: boolean(name='Success', example='True'),
  usage?: {
    inputTokens?: int32(name='InputTokens', example='500'),
    outputTokens?: int32(name='OutputTokens', example='700'),
    totalTokens?: int32(name='TotalTokens', example='1200'),
  }(name='Usage'),
  httpStatusCode?: string(name='httpStatusCode', example='200'),
}

model RunLegalAdviceConsultationResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RunLegalAdviceConsultationResponseBody(name='body'),
}

/**
 * @summary 法律咨询
 *
 * @param tmpReq RunLegalAdviceConsultationRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return RunLegalAdviceConsultationResponse
 */
async function runLegalAdviceConsultationWithOptions(workspaceId: string, tmpReq: RunLegalAdviceConsultationRequest, headers: map[string]string, runtime: Util.RuntimeOptions): RunLegalAdviceConsultationResponse {
  Util.validateModel(tmpReq);
  var request = new RunLegalAdviceConsultationShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.assistant)) {
    request.assistantShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.assistant, 'assistant', 'json');
  }
  if (!Util.isUnset(tmpReq.thread)) {
    request.threadShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.thread, 'thread', 'json');
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.appId)) {
    body['appId'] = request.appId;
  }
  if (!Util.isUnset(request.assistantShrink)) {
    body['assistant'] = request.assistantShrink;
  }
  if (!Util.isUnset(request.stream)) {
    body['stream'] = request.stream;
  }
  if (!Util.isUnset(request.threadShrink)) {
    body['thread'] = request.threadShrink;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RunLegalAdviceConsultation',
    version = '2024-06-28',
    protocol = 'HTTPS',
    pathname = `/${OpenApiUtil.getEncodeParam(workspaceId)}/farui/legalAdvice/consult`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 法律咨询
 *
 * @param request RunLegalAdviceConsultationRequest
 * @return RunLegalAdviceConsultationResponse
 */
async function runLegalAdviceConsultation(workspaceId: string, request: RunLegalAdviceConsultationRequest): RunLegalAdviceConsultationResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return runLegalAdviceConsultationWithOptions(workspaceId, request, headers, runtime);
}

model RunSearchCaseFullTextRequest {
  appId?: string(name='appId', example='farui'),
  filterCondition?: {
    caseNo?: string(name='caseNo'),
    caseTitle?: string(name='caseTitle'),
  }(name='filterCondition'),
  pageParam?: {
    pageNumber?: int32(name='pageNumber', example='1'),
    pageSize?: int32(name='pageSize', example='10'),
  }(name='pageParam', description='This parameter is required.'),
  query?: string(name='query', description='This parameter is required.'),
  queryKeywords?: [ string ](name='queryKeywords'),
  referLevel?: string(name='referLevel'),
  sortKeyAndDirection?: map[string]string(name='sortKeyAndDirection'),
  thread?: {
    messages?: [ 
      {
        content?: string(name='content'),
        role?: string(name='role', example='user'),
      }
    ](name='messages'),
  }(name='thread'),
}

model RunSearchCaseFullTextShrinkRequest {
  appId?: string(name='appId', example='farui'),
  filterConditionShrink?: string(name='filterCondition'),
  pageParamShrink?: string(name='pageParam', description='This parameter is required.'),
  query?: string(name='query', description='This parameter is required.'),
  queryKeywordsShrink?: string(name='queryKeywords'),
  referLevel?: string(name='referLevel'),
  sortKeyAndDirectionShrink?: string(name='sortKeyAndDirection'),
  threadShrink?: string(name='thread'),
}

model RunSearchCaseFullTextResponseBody = {
  code?: string(name='code', example='null'),
  data?: {
    caseLevel?: string(name='caseLevel'),
    caseResult?: [ 
      {
        caseDomain?: {
          abstractObj?: string(name='abstractObj'),
          appliedLaws?: string(name='appliedLaws'),
          basicCase?: string(name='basicCase'),
          caseBasic?: string(name='caseBasic'),
          caseCause?: string(name='caseCause'),
          caseFeature?: string(name='caseFeature'),
          caseId?: string(name='caseId'),
          caseNo?: string(name='caseNo'),
          caseSummary?: string(name='caseSummary'),
          caseTitle?: string(name='caseTitle'),
          caseType?: string(name='caseType'),
          closeCaseCause?: string(name='closeCaseCause'),
          courtFindOut?: string(name='courtFindOut'),
          courtThink?: string(name='courtThink'),
          dataFrom?: string(name='dataFrom'),
          disputeFocus?: string(name='disputeFocus'),
          disputeFocusTag?: [ string ](name='disputeFocusTag'),
          disputedpoints?: string(name='disputedpoints'),
          documentType?: string(name='documentType'),
          judgReason?: string(name='judgReason'),
          keyfacts?: string(name='keyfacts'),
          legalBasis?: string(name='legalBasis'),
          litigants?: string(name='litigants'),
          litigationParticipant?: string(name='litigationParticipant'),
          openCaseCause?: string(name='openCaseCause'),
          preTrialProcess?: string(name='preTrialProcess'),
          referLevel?: string(name='referLevel'),
          refereeGist?: string(name='refereeGist'),
          sourceContent?: string(name='sourceContent'),
          trialCourt?: {
            city?: string(name='city'),
            commonLevel?: string(name='commonLevel'),
            country?: string(name='country'),
            county?: string(name='county'),
            district?: string(name='district'),
            name?: string(name='name'),
            province?: string(name='province'),
            specialLevel?: string(name='specialLevel', example='“”'),
          }(name='trialCourt'),
          trialDate?: string(name='trialDate', example='2018-09-27'),
          trialLevel?: string(name='trialLevel'),
          trialProcess?: string(name='trialProcess'),
          trialProgram?: string(name='trialProgram'),
          verdict?: string(name='verdict'),
        }(name='caseDomain'),
        mode?: string(name='mode'),
        similarity?: string(name='similarity', example='0.88'),
      }
    ](name='caseResult'),
    currentPage?: int32(name='currentPage', example='1'),
    pageSize?: int32(name='pageSize', example='10'),
    query?: string(name='query'),
    queryKeywords?: [ string ](name='queryKeywords'),
    totalCount?: long(name='totalCount', example='1'),
  }(name='data'),
  httpStatusCode?: long(name='httpStatusCode', example='200'),
  message?: string(name='message'),
  requestId?: string(name='requestId', description='Id of the request', example='C844BE6B-33A9-5AC4-A1AE-97B131849E0F'),
  success?: boolean(name='success', example='True'),
}

model RunSearchCaseFullTextResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RunSearchCaseFullTextResponseBody(name='body'),
}

/**
 * @summary 案例检索
 *
 * @param tmpReq RunSearchCaseFullTextRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return RunSearchCaseFullTextResponse
 */
async function runSearchCaseFullTextWithOptions(workspaceId: string, tmpReq: RunSearchCaseFullTextRequest, headers: map[string]string, runtime: Util.RuntimeOptions): RunSearchCaseFullTextResponse {
  Util.validateModel(tmpReq);
  var request = new RunSearchCaseFullTextShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.filterCondition)) {
    request.filterConditionShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.filterCondition, 'filterCondition', 'json');
  }
  if (!Util.isUnset(tmpReq.pageParam)) {
    request.pageParamShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.pageParam, 'pageParam', 'json');
  }
  if (!Util.isUnset(tmpReq.queryKeywords)) {
    request.queryKeywordsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.queryKeywords, 'queryKeywords', 'json');
  }
  if (!Util.isUnset(tmpReq.sortKeyAndDirection)) {
    request.sortKeyAndDirectionShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.sortKeyAndDirection, 'sortKeyAndDirection', 'json');
  }
  if (!Util.isUnset(tmpReq.thread)) {
    request.threadShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.thread, 'thread', 'json');
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.appId)) {
    body['appId'] = request.appId;
  }
  if (!Util.isUnset(request.filterConditionShrink)) {
    body['filterCondition'] = request.filterConditionShrink;
  }
  if (!Util.isUnset(request.pageParamShrink)) {
    body['pageParam'] = request.pageParamShrink;
  }
  if (!Util.isUnset(request.query)) {
    body['query'] = request.query;
  }
  if (!Util.isUnset(request.queryKeywordsShrink)) {
    body['queryKeywords'] = request.queryKeywordsShrink;
  }
  if (!Util.isUnset(request.referLevel)) {
    body['referLevel'] = request.referLevel;
  }
  if (!Util.isUnset(request.sortKeyAndDirectionShrink)) {
    body['sortKeyAndDirection'] = request.sortKeyAndDirectionShrink;
  }
  if (!Util.isUnset(request.threadShrink)) {
    body['thread'] = request.threadShrink;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RunSearchCaseFullText',
    version = '2024-06-28',
    protocol = 'HTTPS',
    pathname = `/${OpenApiUtil.getEncodeParam(workspaceId)}/farui/search/case/fulltext`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 案例检索
 *
 * @param request RunSearchCaseFullTextRequest
 * @return RunSearchCaseFullTextResponse
 */
async function runSearchCaseFullText(workspaceId: string, request: RunSearchCaseFullTextRequest): RunSearchCaseFullTextResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return runSearchCaseFullTextWithOptions(workspaceId, request, headers, runtime);
}

model RunSearchLawQueryRequest {
  appId?: string(name='appId', example='farui'),
  filterCondition?: {
    lawName?: string(name='lawName'),
  }(name='filterCondition'),
  pageParam?: {
    pageNumber?: int32(name='pageNumber', example='1'),
    pageSize?: int32(name='pageSize', example='10'),
  }(name='pageParam'),
  query?: string(name='query', description='This parameter is required.'),
  queryKeywords?: [ string ](name='queryKeywords'),
  thread?: {
    messages?: [ 
      {
        content?: string(name='content'),
        role?: string(name='role', example='user'),
      }
    ](name='messages'),
  }(name='thread'),
}

model RunSearchLawQueryShrinkRequest {
  appId?: string(name='appId', example='farui'),
  filterConditionShrink?: string(name='filterCondition'),
  pageParamShrink?: string(name='pageParam'),
  query?: string(name='query', description='This parameter is required.'),
  queryKeywordsShrink?: string(name='queryKeywords'),
  threadShrink?: string(name='thread'),
}

model RunSearchLawQueryResponseBody = {
  code?: string(name='code', example='Ok'),
  data?: {
    currentPage?: int32(name='currentPage', example='1'),
    lawResult?: [ 
      {
        lawDomain?: {
          abolitionBasis?: string(name='abolitionBasis'),
          implementYearMonthDate?: string(name='implementYearMonthDate'),
          invalidBasis?: string(name='invalidBasis', example='null'),
          issuingNo?: string(name='issuingNo', example='""'),
          issuingOrgan?: string(name='issuingOrgan'),
          lawId?: string(name='lawId', example='b2274825c8c3bc2343ca73680243ddc8'),
          lawItemId?: string(name='lawItemId', example='ccc209683be1509676174fd6890f24b8'),
          lawName?: string(name='lawName'),
          lawOrder?: string(name='lawOrder'),
          lawSourceContent?: string(name='lawSourceContent'),
          lawTitle?: string(name='lawTitle'),
          modifyBasis?: string(name='modifyBasis', example='"[]"'),
          potencyLevel?: string(name='potencyLevel'),
          releaseYearMonthDate?: string(name='releaseYearMonthDate'),
          thematicClassify?: string(name='thematicClassify', example='null'),
          timeliness?: string(name='timeliness'),
        }(name='lawDomain'),
        similarity?: string(name='similarity', example='0.0050'),
      }
    ](name='lawResult'),
    pageSize?: int32(name='pageSize', example='0'),
    query?: string(name='query'),
    queryKeywords?: [ string ](name='queryKeywords'),
    sortKeyAndDirection?: {
      releaseYearMonthDate?: string(name='releaseYearMonthDate', example='desc'),
      similarity?: string(name='similarity', example='desc'),
    }(name='sortKeyAndDirection'),
    totalCount?: long(name='totalCount', example='0'),
  }(name='data'),
  httpStatusCode?: long(name='httpStatusCode', example='200'),
  message?: string(name='message'),
  requestId?: string(name='requestId', description='Id of the request', example='05062567-EB51-50F6-AF56-0BE44955848D'),
  success?: boolean(name='success', example='true'),
}

model RunSearchLawQueryResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RunSearchLawQueryResponseBody(name='body'),
}

/**
 * @summary 法规搜索
 *
 * @param tmpReq RunSearchLawQueryRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return RunSearchLawQueryResponse
 */
async function runSearchLawQueryWithOptions(workspaceId: string, tmpReq: RunSearchLawQueryRequest, headers: map[string]string, runtime: Util.RuntimeOptions): RunSearchLawQueryResponse {
  Util.validateModel(tmpReq);
  var request = new RunSearchLawQueryShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.filterCondition)) {
    request.filterConditionShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.filterCondition, 'filterCondition', 'json');
  }
  if (!Util.isUnset(tmpReq.pageParam)) {
    request.pageParamShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.pageParam, 'pageParam', 'json');
  }
  if (!Util.isUnset(tmpReq.queryKeywords)) {
    request.queryKeywordsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.queryKeywords, 'queryKeywords', 'json');
  }
  if (!Util.isUnset(tmpReq.thread)) {
    request.threadShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.thread, 'thread', 'json');
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.appId)) {
    body['appId'] = request.appId;
  }
  if (!Util.isUnset(request.filterConditionShrink)) {
    body['filterCondition'] = request.filterConditionShrink;
  }
  if (!Util.isUnset(request.pageParamShrink)) {
    body['pageParam'] = request.pageParamShrink;
  }
  if (!Util.isUnset(request.query)) {
    body['query'] = request.query;
  }
  if (!Util.isUnset(request.queryKeywordsShrink)) {
    body['queryKeywords'] = request.queryKeywordsShrink;
  }
  if (!Util.isUnset(request.threadShrink)) {
    body['thread'] = request.threadShrink;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RunSearchLawQuery',
    version = '2024-06-28',
    protocol = 'HTTPS',
    pathname = `/${OpenApiUtil.getEncodeParam(workspaceId)}/farui/search/law/query`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 法规搜索
 *
 * @param request RunSearchLawQueryRequest
 * @return RunSearchLawQueryResponse
 */
async function runSearchLawQuery(workspaceId: string, request: RunSearchLawQueryRequest): RunSearchLawQueryResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return runSearchLawQueryWithOptions(workspaceId, request, headers, runtime);
}

